package wode.entity;
import wode.utils.PUtils;
import wode.view.GamePanel;
import wode.view.GamePanel.*;
import java.awt.*;
import java.util.LinkedList;
import java.util.List;

public class FightePlane extends GameObject{
    List<Zidan> arrayList=new LinkedList<>();
    List<Zidan> arrayList2=new LinkedList<>();
   public static Image image1=PUtils.getImage("images/zdj.png");//获取图片地址
   public static Image image2=PUtils.getImage("images/zdj.png");//获取图片地址
   public static Image images=PUtils.getImage("images/zd.png");//获取图片地址
    public FightePlane(){
        x=300;
        y=830;
        witdh=120;
        height=120;
        new Duogezidan().start();//创建多个子弹
    }
    @Override
    public void drawMe(Graphics g) {
        g.drawImage(image1,x,y,witdh,height,null);//画出战斗机
        g.drawImage(image2,x+130,y+75,witdh-80,height-90,null);//画出僚机
        for (int i = 0; i < arrayList.size(); i+=3) {
            arrayList.get(i).drawMe(g);
        }
        for (int i = 0; i < arrayList2.size(); i++) {
            arrayList2.get(i).drawMe(g);
        }
    }
    @Override
    public Rectangle getRect() {
        return  new Rectangle(x,y,witdh,height);
    }
    class Zidan extends GameObject{
        public Zidan(){
            witdh=30;
            height=120;
        }
        @Override
        public void drawMe(Graphics g) {
            g.drawImage(images,x,y,witdh,height,null);//画出子弹
            y-=3;
        }

        @Override
        public Rectangle getRect() {
            return new Rectangle(x,y,witdh,height);
        }
    }
    class Duogezidan extends Thread{
        @Override
        public void run() {
            while (true){
                try {
                    Zidan zidan1 =new Zidan();
                    Zidan zidan2 =new Zidan();
                    arrayList.add(zidan1);
                    zidan1.x=x+133;
                    zidan1.y=y;
                    arrayList2.add(zidan2);
                    zidan2.x=x+50;
                    zidan2.y=y;
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}